// void, Obj This, Obj other

ObjList ol_unit;
Hero this;
Unit u;
ItemHolder holder;
point pt, p, dpt, ph;
int i;

Sleep(10);
this = This.AsHero;
if (!.IsValid)
	return;
//pr("hero getitems");
if(.item_count == .max_items) return;

if(IsAIPlayer(.player)){
	holder = other.AsItemHolder;
	if (!holder.IsValid)
		return;

	if(.PathTo(holder, .FormRadius, 0) > .sight)
	{
		.FormSetupAndMoveTo(holder, GetConst("GiveDistance"), 0, true);
		while(.HasPath)
			.FormKeepMoving(1500);
	}

	.army.SetCommand("idle");
	while(!.Goto(holder, GetConst("GiveDistance"), 1500, false, 5000));

} else {

	if(.HasItem("irage_battle")) return;
	if(.HasItem("irage_battle_stand")) return;
	if(.HasItem("igreat_charge")) return;
	if(.HasItem("iretreat_notai")) return;

	holder = other.AsItemHolder;
	if(!holder.IsValid)
		return;

	pt = Point(rand(100), rand(100));
	if(.PathTo(holder, .FormRadius, 0) > .sight)
	{
		.FormSetupAndMoveTo(holder.pos+pt, GetConst("GiveDistance"), 0, true);
		while(.HasPath){
			.FormKeepMoving(1500);
		}
	}
	.army.SetCommand("idle");
	ph = holder.pos;
	while(!.Goto(holder, GetConst("GiveDistance"), 1500, true, 10000)){
		ol_unit = Intersect(ObjsInCircle(.pos, 160, "Military"), ClassPlayerObjs("Military", .player)).GetObjList();
		for(i = 0; i < ol_unit.count; i += 1){
			u = ol_unit[i].AsUnit;
			dpt = GetVecByDir(.GetDir(), 200+rand(100));
			p = ph+dpt;
			if(u.IsValid){
				if(!u.IsHeirOf("Hero"))
					if(!u.IsHeirOf("Sentry"))
						if(u.command == "idle")
							u.SetCommand("move", p);
			}
			Sleep(10+rand(10));
		}
		//pr("nie moge dojsc");
	}
}
if(holder.IsValid)
	.OpenItemHolder(holder);

//pr(.DistTo(holder.pos));
if (.AI)
	return;
if (.HasArmy) 
	while (!.Goto(.posRH, 0, 1500, false, 5000));
